package com.xiaov.android.games.my3d;

import com.xiaov.android.games.my3d.mesh.SimplePlane;

public class SelectPlane extends SimplePlane implements Selectable {

	OnClickedListener onClickedListener;
	OnSelectedListener onSelectedListener;
	
	private int clicked = 0;
	public boolean isSelected = false;
	
	public SelectPlane(float width, float height){
		super(width, height);
	}
	

	public void setOnClickedListener(OnClickedListener onClickedListener) {
		this.onClickedListener = onClickedListener;
	}
	
	public void setOnSelectedListener(OnSelectedListener onSelectedListener) {
		this.onSelectedListener = onSelectedListener;
	}


	@Override
	public void onSelected() {
		// TODO Auto-generated method stub
		changeCTextureId(1);
		clicked = 1;
		isSelected = true;
		if(this.onSelectedListener != null){
			this.onSelectedListener.onSelected();
		}
	}

	@Override
	public void onUnSelected() {
		// TODO Auto-generated method stub
		changeCTextureId(0);
		isSelected = false;
		if(this.onSelectedListener != null){
			this.onSelectedListener.onUnSelected();
		}
		if(clicked == 1){
			clicked = 0;
			if(this.onClickedListener != null){
				this.onClickedListener.onClicked();
			}
		}
	}

	private void changeCTextureId(int index){
		cTextureId = index;
		cTextureId %= TEXTURE_NUM;
	}
	
}
